package com.lft.com.oilgas.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lft.com.oilgas.entity.Merchant;
import com.lft.com.oilgas.entity.Ordere;
import com.lft.com.oilgas.mapper.MerchantMapper;
import com.lft.com.oilgas.mapper.OrdereMapper;
import com.lft.com.oilgas.service.IOrdereService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author tyqw
 * @since 2024-09-10
 */
@Service
public class OrdereServiceImpl implements IOrdereService {
    @Autowired
    private OrdereMapper ordereMapper;

    @Autowired
    private MerchantMapper merchantMapper;

    @Override
    public List<Ordere> selectAll(Integer id) {
        LambdaQueryWrapper<Ordere> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Ordere::getDriverId, id);
        return ordereMapper.selectList(queryWrapper);
    }

    @Override
    public void hexiao(Map map) {
        String ding = (String) map.get("ding");
        String code = (String) map.get("code");
        String id = (String) map.get("id");
        Ordere ordere = ordereMapper.selectById(ding);
         boolean a= ordere.getCode().equals(code);
        System.out.println(a);
        if(ordere!=null){
            if(ordere.getCode().equals(code)){
                Merchant merchant = merchantMapper.selectById(id);
                merchant.setIntegral(merchant.getIntegral()+ordere.getAmount());
                merchantMapper.updateById(merchant);
                ordere.setMerchantld(merchant.getId());
                ordereMapper.updateById(ordere);
            }
        }
    }

    @Override
    public List<Ordere> selecthxdan(Integer id) {
        LambdaQueryWrapper<Ordere> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Ordere::getMerchantld, id);
        List<Ordere> orderes = ordereMapper.selectList(queryWrapper);
        return orderes;
    }
}
